﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using AspectCore.DynamicProxy;

namespace ConsoleAppTemp.AspectCore
{
    class CustomInterceptorAttribute : AbstractInterceptorAttribute
    {
        public override async Task Invoke(AspectContext context, AspectDelegate next)
        {
            try
            {
                Console.WriteLine($"Before service {context.Implementation}::{context.ProxyMethod} call.");
                Console.WriteLine(context.ReturnValue);
                await next(context);
                Console.WriteLine($"result:{context.ReturnValue}");
            }
            catch (Exception)
            {
                Console.WriteLine("Service threw an exception!");
                throw;
            }
            finally
            {
                Console.WriteLine("After service call.");
            }
        }
    }
}
